﻿using System;
using System.Windows;
using System.Windows.Input;
using SKQMSLib;

namespace WPF_GUI
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private bool digitGrouping = true;

        private void solveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string input = inputTextBox.Text;
                LinearAlgebraicEquation equation = new LinearAlgebraicEquation(input);
                resultLabel.Content = equation.GetSolution(digitGrouping);
            }
            catch (InvalidSignPositionException ex) { resultLabel.Content = ex.Message;}
            catch (UnkownCharacterException ex) { resultLabel.Content = ex.Message; }
            catch (NumberOutOfBoundsException ex) { resultLabel.Content = ex.Message; }
            catch (ParenthesisException ex) { resultLabel.Content = ex.Message;  }
            catch (UnknownRelatedException ex) { resultLabel.Content = ex.Message; }
            catch (DivideByZeroException ex) { resultLabel.Content = ex.Message;  }
        }

        private void inputTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter) solveButton_Click(sender, e);
        }

        private void digitCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            digitGrouping = true;
        }

        private void digitCheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            digitGrouping = false;
        }
    }
}
